<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx}/static/css/plugins/chosen/chosen.css" rel="stylesheet">
<link href="${ctx}/static/css/plugins/jsTree/default/style.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="usersForm">
							<div class="form-group">
								<label class="col-sm-3 control-label">登录名：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" name="loginName">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">密码：</label>
								<div class="col-sm-8">
									<input type="password" class="form-control" name="password">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">真实名：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" name="realName">
								</div>
							</div>
							<!-- <div class="form-group">
								<label class="col-sm-3 control-label">工号：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" name="no">
								</div>
							</div> -->
							<div class="form-group">
								<label class="col-sm-3 control-label">角色：</label>
								<div class="col-sm-8">
									<sys:ajaxselect id="roleId" name="roleId" url="${ctx }/role/selectRoleList" text="请选择权限" multiple='false' value="" selText="roleName"
										selValue="id" style="width: 350px; " onchange="" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">机构管理：</label>
								<div class="col-sm-8">
									<sys:treeSelect id="organizationId" name="organizationId" url="${ctx}/organization/treeList" title="请选择机构" value="" isCheck="false"
										labelValue="" onchange="" showBoxType="text" isSearch="true" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">手机号码：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" name="mobile">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">邮箱：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" name="email">
								</div>
							</div>

							<div class="form-group">
								<label class="col-sm-3 control-label">备注：</label>
								<div class="col-sm-8">
									<textarea class="form-control" name="remarks"> </textarea>
								</div>
							</div>

							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<shiro:hasPermission name="user_add">
										<button class="btn btn-primary" type="submit">保存内容</button>
									</shiro:hasPermission>
								</div>
							</div>
						</form>

						<div align="center">
							<button class="btn btn-outline btn-danger" type="" id="closeIframe">关闭</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script src="${ctx}/static/js/plugins/jsTree/jstree.min.js"></script>
	<script src="${ctx}/static/js/plugins/chosen/chosen.jquery.js"></script>
	<script src="${ctx}/static/js/plugins/CryptoJS/core.js"></script>
	<script src="${ctx}/static/js/plugins/CryptoJS/cipher-core.js"></script>
	<script src="${ctx}/static/js/plugins/CryptoJS/tripledes.js"></script>
	<script src="${ctx}/static/js/plugins/CryptoJS/mode-ecb.js"></script>
	<script src="${ctx}/static/js/plugins/CryptoJS/enc-base64.js"></script>
	<script type="text/javascript">
		$('#closeIframe').click(function() {
			closeParentWindow();
		});
		$().ready(function() {

			var e = "<i class='fa fa-times-circle'></i> ";
			$("#usersForm").validate({
				rules : {
					loginName : {
						required : true,
						abc : true,
						minlength : 2,
						maxlength : 20
					},
					password : {
						required : true,
						minlength : 6,
						maxlength : 20
					},
					realName : {
						required : true,
						minlength : 2,
						maxlength : 20
					},
					roleId : {
						required : true,
					},
					remarks : {
						maxlength : 255
					},
					mobile : {
						required : true,
						mobile : true
					},
					email : {
						email : true
					},
					/* no : {
						abc : true,
						minlength : 2,
						maxlength : 20
					}, */
					organizationId : {
						required : true
					}
				},
				messages : {
					loginName : e + "${fns:getErrorMessage('ERROR_LOGIN_NAME')}",
					realName : e + "${fns:getErrorMessage('ERROR_REAL_NAME')}",
					roleId : e + "${fns:getErrorMessage('ERROR_USER_ROLE')}",
					remarks : e + "${fns:getErrorMessage('ERROR_REMARKS')}",
					mobile : e + "${fns:getErrorMessage('ERROR_MOBILE')}",
					email : e + "${fns:getErrorMessage('ERROR_EMAIL')}",
					no : e + "${fns:getErrorMessage('ERROR_USER_NO')}",
					organizationId : e + "${fns:getErrorMessage('ERROR_ORG_ID')}",
					password : e + "${fns:getErrorMessage('ERROR_PSWD')}",

				},
				submitHandler : function(form) {
					var data = formToJson("usersForm");
					if (!data.roleId) {
						sighMsg("请选择角色！");
						return false;
					}
					data.password = encryptByDES(data.password, "${fnc:getCookieValue('XSRF-TOKEN')}".split('-').join(''));
					$.post(basePath + "/user/insert", data, function(data) {
						if (data.success) {
							succuceMsg(data.msg);
							parent.$("#queryTable").bootstrapTable('refresh');
							delayCloseParentWindow();
						} else {
							errorMsg(data.msg);
						}
					}, "json");
				}
			});
		});
		var config = {
			".chosen-select" : {},
			".chosen-select-deselect" : {
				allow_single_deselect : !0
			},
			".chosen-select-no-single" : {
				disable_search_threshold : 10
			},
			".chosen-select-no-results" : {
				no_results_text : "Oops, nothing found!"
			},
			".chosen-select-width" : {
				width : "95%"
			}
		};
		for ( var selector in config)
			$(selector).chosen(config[selector]);
	</script>
</body>
</html>